home *** CD-ROM | disk | FTP | other *** search
- /****************************/
- /* TEXTURE.C */
- /****************************/
-
-
- /***************/
- /* EXTERNALS */
- /***************/
-
- #include <qd3d.h>
- #include <QD3DShader.h>
- #include <QD3DStorage.h>
- #include <qdoffscreen.h>
-
-
- /****************************/
- /* PROTOTYPES */
- /****************************/
-
- void LoadMyTextureMap(void);
- TQ3ShaderObject GetMyTextureMapFromPICT(long textureRezID);
- void CreateMyTexturePixmapData(PicHandle pict, TQ3StoragePixmap *pixmapData);
-
- extern void DoFatalAlert(Str255 s);
-
-
- /****************************/
- /* CONSTANTS */
- /****************************/
-
-
- /**********************/
- /* VARIABLES */
- /**********************/
-
- TQ3ShaderObject gMyTextureShaderObject;
-
-
- /***************** LOAD MY TEXTUREMAP *****************/
-
- void LoadMyTextureMap(void)
- {
- gMyTextureShaderObject = GetMyTextureMapFromPICT(128);
- }
-
-
-
- /**************** GET MY TEXTURE MAP FROM PICT ***********************/
- //
- // Loads a PICT resource and returns a shader object which is
- // based on the PICT converted to a texture map.
- //
- // INPUT: textureRezID = resource ID of texture PICT to get.
- //
- // OUTPUT: TQ3ShaderObject = shader object for texture map.
- //
-
- TQ3ShaderObject GetMyTextureMapFromPICT(long textureRezID)
- {
- PicHandle picture;
- TQ3StoragePixmap pixmap;
- TQ3TextureObject texture;
- TQ3ShaderObject shader;
-
-
- /* LOAD PICT RESOURCE */
-
- picture = GetPicture(textureRezID);
- if (picture == nil)
- DoFatalAlert("\pUnable to load texture PICT resource");
-
-
- /* SET PIXMAP DATA FOR PICT */
-
- CreateMyTexturePixmapData(picture,&pixmap);
-
-
- /* MAKE NEW PIXMAP TEXTURE OBJECT */
-
- texture = Q3PixmapTexture_New (&pixmap);
- if (texture == nil)
- DoFatalAlert("\pError calling Q3PixmapTexture_New!");
-
- shader = Q3TextureShader_New (texture);
- if (shader == nil)
- DoFatalAlert("\pError calling Q3TextureShader_New!");
-
-
- /* DISPOSE OF UNNEEDED THINGS */
-
- Q3Object_Dispose (texture);
- Q3Object_Dispose (pixmap.image); // Disposes of extra reference to storage obj
- // from CreateMyTexturePixmapData
-
- ReleaseResource((Handle)picture);
-
- return(shader);
- }
-
-
- /******************** CREATE MY TEXTURE PIXMAP DATA ********************/
- //
- // This routine takes a PICT, draws it into a GWorld, then uses the GWorld
- // do define the parameters for a Storage Pixmap object. The object is not made
- // here, but the data is passed back - the calling routine uses it to create
- // the TQ3StoragePixmap object.
- //
- // INPUT : pict = PICT resource handle
- //
- // OUTPUT : pixmapData = pointer to TQ3StoragePixmap data structure
- //
-
- void CreateMyTexturePixmapData(PicHandle pict, TQ3StoragePixmap *pixmapData)
- {
- Ptr pixAddr;
- Rect rectGW;
- GWorldPtr pGWorld,oldGW;
- PixMapHandle hPixMap;
- OSErr myErr;
- GDHandle oldGD;
- unsigned long size,mapSizeX,mapSizeY,rowBytes;
- TQ3StorageObject storageObj;
-
-
-
- /* CALC SIZE OF PICT */
-
- mapSizeX = (**pict).picFrame.right - (**pict).picFrame.left;
- mapSizeY = (**pict).picFrame.bottom - (**pict).picFrame.top,
-
-
- /* CREATE A GWORLD TO DRAW PICT */
-
- SetRect(&rectGW, 0, 0, mapSizeX, mapSizeY); // set dimensions
- myErr = NewGWorld(&pGWorld, 32, &rectGW, 0, 0, 0L); // make 32 bit gworld (must be 32bit!)
- if (myErr)
- DoFatalAlert("\pError making texture GWorld!");
-
-
- /* CALC GWORLD'S PIXMAP ADDR & ROWBYTES */
-
- hPixMap = GetGWorldPixMap(pGWorld);
- pixAddr = GetPixBaseAddr(hPixMap); // get addr of pixels
- rowBytes = (unsigned long)(**hPixMap).rowBytes & 0x3fff; // calc rowbytes
-
-
- /* DRAW PICTURE INTO GWORLD */
-
- GetGWorld(&oldGW, &oldGD); // save current port
- SetGWorld(pGWorld, nil); // set port to GWorld
- LockPixels(hPixMap); // lock pixels
- EraseRect(&rectGW); // clear the GWorld
- DrawPicture(pict, &rectGW); // draw PICT
- SetGWorld(oldGW, oldGD); // restore port
-
-
- /* CREATE A MEMORY STORAGE OBJECT */
-
- size = rowBytes * mapSizeY; // memory = rowBytes * #rows
- storageObj = Q3MemoryStorage_New((unsigned char *)pixAddr,size); // make new storage object
-
-
- /* SET PIXMAP DATA FIELDS */
-
- pixmapData->image = storageObj; // image = storage object
- pixmapData->width = mapSizeX; // set pixel width
- pixmapData->height = mapSizeY; // set pixel height
- pixmapData->rowBytes = rowBytes; // set rowBytes
- pixmapData->pixelSize = 32; // 32 bit depth
- pixmapData->pixelType = kQ3PixelTypeRGB32; // ditto
- pixmapData->bitOrder = kQ3EndianBig; // Mac bit & byte order
- pixmapData->byteOrder = kQ3EndianBig;
- }
-
-
-
-
-
-